<template>
  <el-dialog
    class="modify-class"
    width="800px"
    :title="title"
    visible
    :close-on-click-modal="false"
    :before-close="beforeClose"
  >
  <el-form class="modify-form mt20" :model="formData" label-width="110px">
    <el-form-item label="系统代号" prop="sysCode">
      <el-input
        class="input"
        v-model="formData.sysCode"
        placeholder="请输入系统代号"
      />
    </el-form-item>
     <el-form-item label="系统编号" prop="sysName">
      <el-input
        class="input"
        v-model="formData.sysNo"
        placeholder="请输入系统名称"
      />
    </el-form-item>
    <el-form-item label="系统名称" prop="sysName">
      <el-input
        class="input"
        v-model="formData.sysName"
        placeholder="请输入系统名称"
      />
    </el-form-item>
    <el-form-item label="设计单位" prop="designOrg">
      <el-input
        class="input"
        v-model="formData.designOrg"
        placeholder="请输入设计单位"
      />
    </el-form-item>
    <el-form-item label="生产单位" prop="productionOrg">
      <el-input
        class="input"
        v-model="formData.productionOrg"
        placeholder="请输入生产单位"
      />
    </el-form-item>
    <el-form-item label="齐套单位" prop="matchOrg">
      <el-input
        class="input"
        v-model="formData.matchOrg"
        placeholder="请输入齐套单位"
      />
    </el-form-item>
    <el-form-item label="是否验收合格">
      <el-select v-model="formData.qualified" placeholder="请选择" style="width:100%">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
     <el-form-item label="上传报告">
      <div class="file-wrap">
          <span class="span">{{report}}</span>
          <import-data :api-url="uploadFile" title="上传报告" @upload-success="uploadSuccess1"/>
      </div>
    </el-form-item>
     <el-form-item label="上传结论">
      <div class="file-wrap">
        <span class="span">{{conclusion}}</span>
        <import-data :api-url="uploadFile" title="上传结论" @upload-success="uploadSuccess2"/>
       </div>
    </el-form-item>
  </el-form>
  <div class="dialog-footer" slot="footer">
    <el-button class="btn-comfirm" type="primary" @click="saveHandle">确认</el-button>
    <el-button class="btn-cancel" @click="cancelHandle">取消</el-button>
  </div>
  </el-dialog>
</template>

<script>
import acceptanceApis from '@/apis/overview/acceptance.js'
import ImportData from '@/components/ImportData.vue'
export default {
  props: {
    dataObj: {
      type: Object,
      default: null
    }
  },
  components: { ImportData },
  data() {
    return {
      uploadFile:acceptanceApis.uploadFile,
      options: [{
          value: 'Y',
          label: '合格'
        }, {
          value: 'N',
          label: '不合格'
      }],
      title: '新增系统验收',
      formData: {
            id: this.id,
            sysCode: '',
            sysName: '',
            designOrg: '',
            productionOrg: '',
            matchOrg: ''
        },
      importParams:{},
      conclusion:'',
      report:''
    }
  },
  created() {
      if (this.dataObj) {
          this.title = '新增系统验收';
          this.formData = this.dataObj
      }
  },
  methods: {
    uploadSuccess1(e) {
      this.formData.reportAttachId = e.id
      this.report = e.fileName
      console.log(this.formData.reportAttachId)
    },
    uploadSuccess2(e) {
      this.formData.resAttachId = e.id
      this.conclusion = e.fileName
    },
    close(refresh) {
      this.$emit("close", refresh);
    },
    beforeClose() {
      this.close(false);
    },
    saveHandle() {
      let model = {}
      if(!this.formData.qualified){
        if(this.formData.reportAttachId){
           model.reportAttachId = this.formData.reportAttachId
        }
        if(this.formData.resAttachId){
           model.resAttachId = this.formData.resAttachId
        }
        model.modelId = this.formData.modelId
        model.sysCode = this.formData.sysCode
        model.sysName = this.formData.sysName
        model.designOrg = this.formData.designOrg
        model.productionOrg = this.formData.productionOrg
        model.matchOrg = this.formData.matchOrg
        model.sysNo = this.formData.sysNo
      }else{
         if(this.formData.reportAttachId){
           model.reportAttachId = this.formData.reportAttachId
        }
        if(this.formData.resAttachId){
           model.resAttachId = this.formData.resAttachId
        }
        model.modelId = this.formData.modelId
        model.sysCode = this.formData.sysCode
        model.sysName = this.formData.sysName
        model.designOrg = this.formData.designOrg
        model.productionOrg = this.formData.productionOrg
        model.matchOrg = this.formData.matchOrg
        model.qualified = this.formData.qualified
        model.sysNo = this.formData.sysNo
      }
      
      acceptanceApis.addSystemList(model).then(() => {
        this.$message.success('新增成功')
        this.formData.sysCode = '';
        this.formData.sysNo = '';
        this.formData.sysName = '';
        this.formData.designOrg = '';
        this.formData.productionOrg = '';
        this.formData.matchOrg = '';
        this.formData.qualified = '';
        this.formData.reportAttachId = '';
        this.formData.resAttachId = '';
        this.close(true)
        this.$emit("saveSuccess");
      })
    },
    cancelHandle() {
      this.close(false)
    }
  }
}
</script>

<style lang="scss">
.el-input--suffix .el-input__inner{
  background: #e7e9f2;
}
.file-wrap{
  display: flex;
  .span{
    margin-right:20px;
    color:#409eff
  }
}
</style>